package com.wordcount;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.VoidFunction;

public class Java_Sample {
    public static void main(String[] args) {
        SparkConf conf=new SparkConf();

        conf.setMaster("local").setAppName("sample_test");

        JavaSparkContext sc=new JavaSparkContext(conf);

        JavaRDD<String> lines = sc.textFile("./words.txt");

        JavaRDD<String> sample = lines.sample(true, 0.1, 100);

        sample.foreach(new VoidFunction<String>() {
            @Override
            public void call(String s) throws Exception {
                System.out.println(s);
            }
        });


        sc.close();
    }
}
